<?php
    if (isset($_GET['id']))
    {
        $id = intval($_GET['id']);
        $this->contentFile = "Product/Product";
        if (Product::productExists($id))
        {
            $this->view->product = new Product($id);
            $this->view->scripts = array('jquery-1.7.2', 'osmplayer.compressed');
            $this->view->title = $this->view->product->title;
        }
        else
        {
            $this->view->setStatus("Produkt o danym identyfikatorze nie istnieje", false);
        }
    }
    else if (isset($_GET['category']))
    {
        $category = stripslashes($_GET['category']);
        $count = Product::getProductCount("catName = '$category'");
        if ($count > 0)
        {
            $selectedPage = isset($_GET['page']) ? intval($_GET['page']) : 1;
            $this->view->selectedPage = $selectedPage;

            $this->view->data = Product::search(array('category' => $category), ($selectedPage - 1) * ELEMENT_COUNT, ELEMENT_COUNT);
            $this->contentFile = "Product/ProductList";
            $this->view->pageCount = Product::getProductCount("catName = '$category'")/ELEMENT_COUNT + 1;
        }
        else
            $this->view->setStatus("Brak produktów w danej kategorii", false);
    }
?>
